<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :maskClosable="false"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <j-form-container>
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="modelNumber">
                <a-input v-model="model.modelNumber" placeholder="请输入型号"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specifications">
                <a-input v-model="model.specifications" placeholder="请输入规格"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="品牌" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brand">
                <a-input v-model="model.brand" placeholder="请输入品牌"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unit">
                <a-input v-model="model.unit" placeholder="请输入单位"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="材料状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
                <a-radio-group button-style="solid" v-model="model.status">
                  <a-radio-button :value="1">
                    启用
                  </a-radio-button>
                  <a-radio-button :value="2">
                    禁用
                  </a-radio-button>
                </a-radio-group>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="市场价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="marketPrice">
                <a-input-number v-model="model.marketPrice" placeholder="请输入市场价" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="预算价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="estimatedCost">
                <a-input-number v-model="model.estimatedCost" placeholder="请输入预算价" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="成本价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="costPrice">
                <a-input-number v-model="model.costPrice" placeholder="请输入成本价" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>

      </j-form-container>
    </a-spin>
  </j-modal>
</template>

<script>
  import { putAction } from '@/api/manage'

  export default {
    name: 'updateBatchModal',
    components: {

    },
    data () {
      return {
        title:'',
        previewWidth: '70%',
        width: 800,
        visible: false,
        disableSubmit: false,
        model: {},
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },
        confirmLoading: false,
        validatorRules: {

        },
        url: {
          updateBatch: "/ghSupplychainMaterial/updateBatch",
        },
        ids:""
      }
    },
    created() {

    },
    methods: {
      add(ids) {
        this.ids = ids;
        let obj = {status:1};
        this.model = Object.assign({}, obj);
        this.visible = true;
        this.title = "批量修改"
      },
      handleOk () {
        let that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            putAction(this.url.updateBatch, {material:this.model,ids:this.ids}).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit('ok');
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close()
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },
      close () {
        this.visible = false;
        this.model = {};
        this.ids = ""
      },
    }
  }
</script>